// Created by WXX on 2021/11/5 14:30
#include <iostream>
#include <vector>
#include <unordered_map>

using namespace std;

/**
 * 执行用时：132 ms, 在所有 C++ 提交中击败了40.57%的用户
 * 内存消耗：55.2 MB, 在所有 C++ 提交中击败了53.77%的用户
 */
class Solution {
public:
    int longestSubsequence(vector<int>& arr, int d) {

        unordered_map<int, int> f;
        int res = 0;
        for (int x : arr) {
            f[x] = f[x - d] + 1;
            res = max(res, f[x]);
        }
        return res;
    }
};

int main() {

    vector<int> arr = {1, 2, 3, 4};
    cout << Solution().longestSubsequence(arr, 1) << endl;  // 4

    return 0;
}
